package com.bestcem.xm.deliver.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.bestcem.xm.component.mybatis.service.impl.XmServiceImpl;
import com.bestcem.xm.deliver.entity.DeliverCustomLinkDeliver;
import com.bestcem.xm.deliver.entity.DeliverDeliver;
import com.bestcem.xm.deliver.mapper.DeliverCustomLinkDeliverMapper;
import com.bestcem.xm.deliver.mapper.DeliverDeliverMapper;
import com.bestcem.xm.deliver.service.DeliverCustomLinkDeliverService;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

import static com.bestcem.xm.deliver.enums.DeliverStatusEnum.*;

/**
 * @author been
 * @description 针对表【ds_deliver_customlinkdeliver】的数据库操作Service实现
 * @createDate 2022-11-07 13:49:46
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class DeliverCustomLinkDeliverServiceImpl extends XmServiceImpl<DeliverCustomLinkDeliverMapper, DeliverCustomLinkDeliver>
        implements DeliverCustomLinkDeliverService {

    private @NonNull DeliverDeliverMapper deliverDeliverMapper;

    @Override
    public void triggerDeliverStatus(DeliverDeliver deliver, String action) {
        if (StrUtil.equals("start", action)) {
            deliverDeliverMapper.update(null,
                    new UpdateWrapper<DeliverDeliver>().lambda()
                            .eq(DeliverDeliver::getId, deliver.getId())
                            .set(DeliverDeliver::getStatus, DELIVER_STATUS_START.getValue())
                            .set(DeliverDeliver::getDeliverTime, LocalDateTime.now()));
        } else if (StrUtil.equals("finish", action)) {
            deliverDeliverMapper.update(null,
                    new UpdateWrapper<DeliverDeliver>().lambda()
                            .eq(DeliverDeliver::getId, deliver.getId())
                            .set(DeliverDeliver::getStatus, DELIVER_STATUS_FINISH.getValue())
                            .set(DeliverDeliver::getDeliverTime, LocalDateTime.now()));
        } else if (StrUtil.equals("delete", action)) {
            deliverDeliverMapper.update(null,
                    new UpdateWrapper<DeliverDeliver>().lambda()
                            .eq(DeliverDeliver::getId, deliver.getId())
                            .set(DeliverDeliver::getStatus, DELIVER_STATUS_DELETE.getValue())
                            .set(DeliverDeliver::getDeliverTime, LocalDateTime.now()));
        }
    }
}




